﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;

public class ExportConfig
{
    public ExportConfig()
    {
        if (!LoadConfig())
        {
            String curDir = System.IO.Directory.GetCurrentDirectory();
            ExcelPath = curDir;
            ClientCodeOutPutPath = curDir;
            ServerCodeOutPutPath = curDir;
            ClientLanguage = "c#";
            ServerLanguage = "c#";
        }
    }

    public bool LoadConfig()
    {
        string strConfigPath = Path.Combine(Application.StartupPath, configFile);
        if (!File.Exists(strConfigPath))
        {
            return false;
        }
        using (StreamReader r = new StreamReader(strConfigPath))
        {
            ExcelPath = r.ReadLine();
            ClientCodeOutPutPath = r.ReadLine();
            ServerCodeOutPutPath = r.ReadLine();
            ClientLanguage = r.ReadLine();
            ServerLanguage = r.ReadLine();
        }
        return true;
    }

    public bool SaveConfig()
    {
        if (File.Exists(configFile))
        {
            File.SetAttributes(configFile, FileAttributes.Normal);
        }

        StreamWriter w = File.CreateText(configFile);

        w.WriteLine(ExcelPath);
        w.WriteLine(ClientCodeOutPutPath);
        w.WriteLine(ServerCodeOutPutPath);
        w.WriteLine(ClientLanguage);
        w.WriteLine(ServerLanguage);
        w.Close();
        return true;
    }

    const String configFile = "DataFactoryConfig.cfg";
    public String ExcelPath { get; set; }
    public String ClientCodeOutPutPath { get; set; }
    public String ServerCodeOutPutPath { get; set; }
    public string ClientLanguage { get; set; }
    public string ServerLanguage { get; set; }

}
